<!-- 金币明细 -->
<template>
  <div class="table">
    <div class="container">
      <div class="crumbs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>
            <el-icon>
              <Search />
            </el-icon> 查询条件：
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-row :gutter="10">
        <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
          <el-select v-model.trim="searchCondition.type" placeholder="金币分类" clearable class="">
            <el-option v-for="item in state.selectGold" :label="item.dictLabel" :value="item.dictValue"
              :key="item.id"></el-option>
          </el-select>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
          <el-input v-model.trim="searchCondition.mobile" placeholder="手机号" clearable></el-input>
        </el-col>
        <el-col :xl="6" :lg="8" :md="12" :sm="24" style="margin-bottom:10px">
          <el-date-picker v-model="state.queryDate" type="datetimerange" range-separator="至"
            format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始时间"
            @change="changeQueryDate" end-placeholder="结束时间">
          </el-date-picker>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
          <el-button type="success" :icon="Search" :disabled="disabledbtn" @click="searchInfo">搜索</el-button>
          <el-button type="warning" :icon="Refresh" :disabled="disabledbtn"
            @click="resetSearch(customMethods)">重置</el-button>
        </el-col>
      </el-row>
      <div class="crumbs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>查询结果：</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-table :data="tableState.tableList" border class="table" ref="multipleTableRef" v-loading="tableLoading"
        :reserve-selection="true" @row-dblclick="rowDblclick">
        <el-table-column type="index" align="center"> </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="typeName" label="金币分类" align="center">
        </el-table-column>
        <el-table-column prop="mobile" label="手机号" align="center">
        </el-table-column>
        <el-table-column prop="money" label="金额" align="center">
        </el-table-column>
        <el-table-column prop="create_time" label="时间" align="center">
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="primary" size="small" text :icon="View" @click="handleViewEdit(scope.row, 'view', '查看')">
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background @update:current-page="handleCurrentChange" @update:page-size="handleSizeChange"
          layout="total, sizes, prev, pager, next, jumper" :page-size="searchCondition.size"
          :current-page="searchCondition.current" :page-sizes="pageSizes" :total="total" :hide-on-single-page="false">
        </el-pagination>
      </div>
    </div>

    <!-- 新增编辑查看弹出框 -->
    <el-dialog :title="dialogTitle" v-model="editVisible" width="60%" draggable
      :close-on-click-modal="closeOnClickModal" @closed="closedFormDialog">
      <el-form ref="redEnvelopeInfoFormRef" :model="goldInfoForm" v-loading="formLoading" label-width="150px">
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="金币分类：" prop="type">
              <el-select v-model.trim="goldInfoForm.type" placeholder="金币分类" class="">
                <el-option v-for="item in state.selectGold" :label="item.dictLabel" :value="item.dictValue"
                  :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="手机号：" prop="name">
              <el-input v-model.trim="goldInfoForm.mobile" placeholder="手机号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="金额：" prop="method">
              <el-input v-model.trim="goldInfoForm.money" placeholder="金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="时间：" prop="url">
              <el-date-picker v-model="goldInfoForm.create_time" type="datetime" format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <!-- <el-button type="primary" :disabled="disabledbtn" v-if="!isDisabledbtn"
          @click="submitForm('commonResourceInfo', getTableInfo)">确
          定
        </el-button> -->
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { reactive, ref, nextTick, onActivated, onDeactivated, onUnmounted } from 'vue';
import { View, Search, Refresh } from '@element-plus/icons-vue';
import { common as Common } from '@/utils/common.js';
import { useGoldStore } from '@/store/gold';
import { useTable } from '@/hooks/useTable.js';
import { useDialogForm } from '@/hooks/useDialogForm.js';
import { useDictData } from '@/hooks/network/useDictData.js';
const disabledbtn = ref(false);/* 按钮可用与不可用 */
const formLoading = ref(false);/* 表单loading状态 */
const goldStore = useGoldStore();
const state = reactive({
  selectGold: [],/* 红包类型 */
  queryDate: [] /* 查询时间 */
});
let { getDictDataInfo } = useDictData();
let { total, pageSizes, multipleTableRef, tableLoading, tableState, searchCondition,
  handleCurrentChange, handleSizeChange, getTableInfo, searchInfo, resetSearch, batchDelete, deleteInfo, rowDblclick } =
  useTable({
    mobile: '',
    type: '',
    start_create_time: '',
    end_create_time: '',
    current: 1,
    size: 10
  }, 'getGoldLogInfo', disabledbtn);

let { formRef: redEnvelopeInfoFormRef, formData: goldInfoForm, methodType, isDisabledbtn,
  closeOnClickModal, dialogTitle, editVisible, closedFormDialog,
  submitForm } = useDialogForm({
    id: '',
    type: '',
    mobile: '',
    money: '',
    create_time: ''
  }, disabledbtn, handleCustomOperation, formLoading);

/* 查询 创建时间更改事件 */
const changeQueryDate = (data) => {
  if (data !== null) {
    searchCondition.start_create_time = Common.renderTime(
      data[0]
    );
    searchCondition.end_create_time = Common.renderTime(data[1]);
  } else {
    searchCondition.start_create_time = '';
    searchCondition.end_create_time = '';
  }
}

/* 点击编辑按钮 */
const handleViewEdit = (row, code, name) => {
  if ('view' === code) {
    dialogTitle.value = name;
    isDisabledbtn.value = true;
    closeOnClickModal.value = true;
  } else if ('edit' === code) {
    dialogTitle.value = name;
    methodType.value = 'PUT';
  }
  nextTick(() => {
    goldInfoForm.id = row.id;
    goldInfoForm.type = row.type;
    goldInfoForm.mobile = row.mobile;
    goldInfoForm.money = row.money;
    goldInfoForm.create_time = row.create_time;
  });
  editVisible.value = true;
}
/* 重置方法回调函数 */
const customMethods = () => {
  state.queryDate = [];
}

/* 关闭弹框以后的自定义操作 */
function handleCustomOperation () {
  goldInfoForm.id = '';
}

/* 初始化请求类型，红包类型信息 */
getDictDataInfo('GOLD_USE_TYPE', state, 'selectGold');


if (goldStore.mobile === '') getTableInfo();

/* 缓存组件重新插入执行 */
onActivated(() => {
  console.log(goldStore.mobile);
  if (goldStore.mobile === '') return;
  searchCondition.mobile = goldStore.mobile;
  searchCondition.type = '';
  searchCondition.start_create_time = '';
  searchCondition.end_create_time = '';
  customMethods();
  searchInfo();
})

/* 缓存组件移除执行 */
onDeactivated(() => {
  goldStore.mobile = '';
})

/* 卸载组件 */
onUnmounted(() => {
  goldStore.mobile = '';
})

</script>

<style scoped>
/* layout-布局 */
.el-row {
  margin-bottom: 20px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.textAlignCenter {
  text-align: center;
}

/* 修改select的盒模型 */
.el-select {
  display: block;
}

/* 确定按钮的显示与隐藏 */
.displaybtn {
  display: none;
}

/* 修改该属性值  查询条件，查询结果得样式 */
.el-breadcrumb {
  border-bottom: 1px solid #ebeef5;
  padding-bottom: 10px;
}

/* 提示图标设置 */
.icon-wzg-config {
  height: 30px;
  line-height: 30px;
}

/* 修改Switch开关 */
.el-switch {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

/* 修改时间组件的宽度样式 start*/
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

/* end */
</style>
